package cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.controller.admin.ysshop;

import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.controller.admin.ysshop.vo.YsShopExcelVO;
import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.controller.admin.ysshop.vo.YsShopExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.controller.admin.ysshop.vo.YsShopPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.dal.dataobject.ysshop.YsShopDO;
import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.dal.mysql.ysshop.YsShopMapper;
import cn.iocoder.yudao.module.system.controller.admin.mini.other.ysShop.service.ysshop.YsShopService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 易神消费记录")
@RestController
@RequestMapping("/qd/ys-shop")
@Validated
public class YsShopController {

    @Resource
    private YsShopService ysShopService;
    @Resource
    YsShopMapper shopMapper;

//    @PostMapping("/create")
//    @Operation(summary = "创建易神消费记录")
//    @PreAuthorize("@ss.hasPermission('qd:ys-shop:create')")
//    public CommonResult<Integer> createYsShop(@Valid @RequestBody YsShopCreateReqVO createReqVO) {
//        return success(ysShopService.createYsShop(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新易神消费记录")
//    @PreAuthorize("@ss.hasPermission('qd:ys-shop:update')")
//    public CommonResult<Boolean> updateYsShop(@Valid @RequestBody YsShopUpdateReqVO updateReqVO) {
//        ysShopService.updateYsShop(updateReqVO);
//        return success(true);
//    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除易神消费记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('qd:ys-shop:delete')")
    public CommonResult<Boolean> deleteYsShop(@RequestParam("id") Integer id) {
        ysShopService.deleteYsShop(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得易神消费记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('qd:ys-shop:query')")
    public CommonResult getYsShop(@RequestParam("id") Integer id) {
        return success(ysShopService.getYsShop(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得易神消费记录分页")
    @PreAuthorize("@ss.hasPermission('qd:ys-shop:query')")
    public CommonResult getYsShopPage(@Valid YsShopPageReqVO pageVO) {
        return success( ysShopService.getYsShopPage(pageVO));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出易神消费记录 Excel")
    @PreAuthorize("@ss.hasPermission('qd:ys-shop:export')")
    @OperateLog(type = EXPORT)
    public void exportYsShopExcel(@Valid YsShopExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        // 导出 Excel
        List<YsShopExcelVO> datas = new ArrayList<>();
        for (YsShopDO vo : shopMapper.selectList(exportReqVO)) {
            datas.add(new YsShopExcelVO(vo));
        }

        ExcelUtils.write(response, "易神消费记录.xls", "数据", YsShopExcelVO.class, datas);
    }

}
